/**
 * 
 */
var fileUpload = {
	
	/**
	 * 上传附件，带进度条
	 * @param btnId 上传按钮id
	 * @param cfg 设置信息 {onSuccess:callback, type:fileType[image|doc]}
	 * 示例：fileUpload.swfupload("uploadBtn", {convert:true,onSuccess:callbackUpload});
	 */
	swfupload:function(btnId,cfg){
		var btn = $("#"+btnId);
		var formData = cfg.formData ? cfg.formData : {};
		
		cfg.btnId = btnId;
		
		var limit = cfg.limit || 99;
		
		/*var param = "?1=1";
		var attachType = cfg.attachType ? cfg.attachType : "OTHER_ATTACH";
		param  += "&attachType="+attachType;
		var businessCode = cfg.businessCode ? cfg.businessCode : "default";
		param  += "&businessCode="+businessCode;*/
		var types=cfg.type;
		var typeArr = "";
		if(types){
			typeArr = types.split("||");
		}
		
		var fileExt = ""; // 允许上传文件的扩展名
		for(var i=0;i<typeArr.length;i++){
			var type = typeArr[i];
			if(type == "image"){
				fileExt = "*.jpg;*.jpeg;*.gif;*.png"+";"+fileExt;
			} else if(type == "doc"){
				fileExt = "*.doc;*.docx;*.xls;*.xlsx;*.ptt;*.pptx;*.pdf;*.txt"+";"+fileExt;
			} else if(type == "pdf"){
				fileExt = "*.pdf"+";"+fileExt;
			} else if(type == "word"){
				fileExt = "*.doc;*.docx"+";"+fileExt;
			} else {
				fileExt = "*."+type+";"+fileExt;
			}
		}
		var params = {
			'height'        : 25,
			'width'         : 200,
			'fileObjName'   : 'file',
			'formData'      : formData,
			'fileTypeExts'	: fileExt,
			'fileSizeLimit' : cfg.sizeLimit || '50MB', 
			'onSelectError' : onSwfSelectError,
			'overrideEvents' : ['onSelectError','onDialogClose'],
			'swf'      : baseURL + '/js/uploadify/uploadify.swf',
			'uploader' : baseURL + '/os/object/upload',
			'auto' : true,
			'multi' : true,
			'scriptAccess' : 'always',
			'removeTimeout' : 1,
			'successTimeout' : 120,
			'uploadLimit':limit,
			'buttonText' : '<a href="javascript:void(0);">'+localeMsg.common.upload+'</a>',
			'removeCompleted' : true,
			'onUploadStart' : cfg.onUploadStart || function(){},
			'onUploadSuccess' : function(file, data, response) {
				if(response.result == "success"){
					var json = eval('(' + data + ')');
					if(json.result == "success"){
						cfg.onSuccess.call(this, file, json,cfg,attachType);
					}else{
						if(cfg.onFail){
							cfg.onFail.call(this, file, json,cfg);
						}else{
							if(json.type == 'document'){
								alert(localeMsg.attach.typeError);
							}else{
								alert(localeMsg.attach.serverError);
							}
						}
					}
				}else{
					alert(localeMsg.common.contactAdmin);
				}
	    	}
		};
		
		if(cfg.text){
			params.buttonText = cfg.text;
			params.buttonClass='up-text';
			delete params.buttonImage;
		}
		var isHide = btn.attr('_hide');
		// 上传
		btn.uploadify(params);
		
		// 修改上传按钮样式
		$("#" + btnId).attr("style","top:0px");
		$("#" + btnId + "-button").removeAttr("style");
		$("#" + btnId + "-button").removeClass();
		$("#" + btnId).removeClass();
		$("#" + btnId).addClass("s_btnwork upload_btn");
		$("#" + btnId).css("position","relative");
		if(isHide == '1'){
			$("#" + btnId).hide();
		}
		
		function onSwfSelectError(file, errorCode, errorMsg){
			if(errorCode == SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT){
				alert(localeMsg.attach.maxSize+cfg.sizeLimit);
				return false;
			}else if(errorCode == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE){
				alert(localeMsg.attach.attachExist);
				return false;
			}else if(errorCode == SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED){
				alert(localeMsg.attach.maxAttach);
				return false;
			}
		}
	},
	
	/**
	 * 上传成功后的默认回调方法
	 */
	defaultUploadCallback: function() {
		alert(params);
	},
	onSelect: function(file)
	{ 
		//文件名称
		$("#templateName").val(file.name);
	},
	/**
	 * 上传附件，带进度条(安徽多级数据字典的附件类型，主要项目的业务表单使用)
	 * @param btnId 上传按钮id
	 * @cfg 设置信息 {onSuccess:callback, type:fileType[image|doc]}
	 * 示例：fileUpload.swfupload("uploadBtn", {convert:true,onSuccess:callbackUpload});
	 */
	swfuploadTree:function(btnId,cfg){
		var btn = $("#"+btnId);
		var data = cfg.convert ? {'convert':'1'} : {};
		
		cfg.btnId = btnId;
		
		var limit = cfg.limit || 999;
		
		var param = "?companyId="+companyId;
		var attachType = cfg.attachType;
		param  += "&attachType="+attachType;
		var businessCode = cfg.businessCode ? cfg.businessCode : "default";
		param  += "&businessCode="+businessCode;
		var types=cfg.type;
		var typeArr = "";
		if(types){
			typeArr = types.split("||");
		}
		
		var fileExt = ""; // 允许上传文件的扩展名
		for(var i=0;i<typeArr.length;i++){
			var type = typeArr[i];
			if(type == "image"){
				fileExt = "*.jpg;*.jpeg;*.gif;*.png"+";"+fileExt;
			} else if(type == "doc"){
				fileExt = "*.doc;*.docx;*.xls;*.xlsx;*.ptt;*.pptx;*.pdf;*.txt"+";"+fileExt;
			} else if(type == "pdf"){
				fileExt = "*.pdf"+";"+fileExt;
			} else if(type == "word"){
				fileExt = "*.doc;*.docx"+";"+fileExt;
			}else {
			    //按黄楠要求，改成可上传所有文件
				fileExt = "*."+type+";"+fileExt;
			}
		}
		var params = {
			'height'        : 25,
			'width'         : 200,
			'fileObjName'   : 'file',
			'formData'      : data,
			'fileTypeExts'	: fileExt,
			'fileSizeLimit' : cfg.sizeLimit || '50MB', 
			'onSelectError' : onSwfSelectError,
			'overrideEvents' : ['onSelectError','onDialogClose'],
			'swf'      : resourceURL + '/uploadify/uploadify.swf',
			'uploader' : fileURL + '/file/upload'+param,
			'auto' : true,
			'multi' : true,/* 安徽支持批量上传 */
			'scriptAccess' : 'always',
			'removeTimeout' : 1,
			'successTimeout' : 120,
			'uploadLimit':limit,
			'buttonText' : '<a href="javascript:void(0);">'+localeMsg.attach.upload+'</a>',
			'removeCompleted' : true,
			'onUploadSuccess' : function(file, data, response) {
				if(response == true){
					var json = eval('(' + data + ')');
					if(json.success == true){
						cfg.onSuccess.call(this, file, json,cfg,attachType);
					}else{
						if(cfg.onFail){
							cfg.onFail.call(this, file, json,cfg);
						}else{
							if(json.type == 'document'){
								alert(localeMsg.attach.typeError);
							}else{
								alert(localeMsg.attach.serverError);
							}
						}
					}
				}else{
					alert(localeMsg.common.contactAdmin);
				}
	    	}
		};
		
		if(cfg.text){
			params.buttonText = cfg.text;
			params.buttonClass='up-text';
			delete params.buttonImage;
		}
		var isHide = btn.attr('_hide');
		// 上传
		btn.uploadify(params);
		
		// 修改上传按钮样式
		$("#" + btnId).attr("style","top:0px");
		$("#" + btnId + "-button").removeAttr("style");
		$("#" + btnId + "-button").removeClass();
		$("#" + btnId).removeClass();
		$("#" + btnId).addClass("s_btnwork upload_btn");
		$("#" + btnId).css("position","relative");
		if(isHide == '1'){
			$("#" + btnId).hide();
		}
		
		function onSwfSelectError(file, errorCode, errorMsg){
			if(errorCode == SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT){
				alert(localeMsg.attach.maxSize+cfg.sizeLimit);
				return false;
			}else if(errorCode == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE){
				alert(localeMsg.attach.attachExist);
				return false;
			}else if(errorCode == SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED){
				alert(localeMsg.attach.maxAttach);
				return false;
			}
		}
	}
}

var fileUploadList = {
		
		/**
		 * 上传附件，带进度条
		 * @param btnId 上传按钮id
		 * @cfg 设置信息 {onSuccess:callback, type:fileType[image|doc]}
		 * 示例：fileUpload.swfupload("uploadBtn", {convert:true,onSuccess:callbackUpload});
		 */
		swfupload:function(btnId,cfg){
			var btn = $("#"+btnId);
			var data = {};
			var url  = cfg.url + ';jsessionid=' + $.cookie('JSESSIONID');
			var limit = cfg.limit || 99;
			
			var fileExt = null; // 允许上传文件的扩展名
			if(cfg.type == "image"){
				fileExt = "*.jpg;*.jpeg;*.gif;*.png";
			} else if(cfg.type == "doc"){
				fileExt = "*.doc;*.docx;*.xls;*.xlsx;*.ptt;*.pptx;*.pdf;*.txt";
			} else if(cfg.type == "pdf"){
				fileExt = "*.pdf";
			} else if(cfg.type == "word"){
				fileExt = "*.doc;*.docx";
			}else {
			    //按黄楠要求，改成可上传所有文件
				fileExt = "*.*";
			}
			var params = {
				'height'        : 25,
				'width'         : 24,
				'fileObjName'   : 'file',
				'formData'      : data,
				'fileTypeExts'	: fileExt,
				'fileSizeLimit' : cfg.sizeLimit || '30MB', 
				'onSelectError' : onSwfSelectError,
				'overrideEvents' : ['onSelectError','onDialogClose'],
				'swf'      : resourceURL + '/uploadify/uploadify.swf',
				'uploader' : url,
				'auto' : true,
				'multi' : false,
				'scriptAccess' : 'always',
				'removeTimeout' : 1,
				'successTimeout' : 120,
				'uploadLimit':limit,
				'buttonText' :'<a href="javascript:void(0);">'+ cfg.text || localeMsg.attach.upload+'</a>',
				'removeCompleted' : true,
				'onselect': function(file){
					if(cfg.onSelect){
						cfg.onSelect.call(this, file);
					}
				},
				'onSelect' : function() {
					try {
						if (getParamStr) {
							var paramStr = getParamStr();
							if ($('#importData').length > 0) {
								$('#importData').uploadify('settings', 'formData', {
									'paramStr' : paramStr
								});
							}
							if ($('#importData02').length > 0) {
								$('#importData02').uploadify('settings', 'formData', {
									'paramStr' : paramStr
								});
							}
							if ($('#importData03').length > 0) {
								$('#importData03').uploadify('settings', 'formData', {
									'paramStr' : paramStr
								});
							}
							if ($('#importData04').length > 0) {
								$('#importData04').uploadify('settings', 'formData', {
									'paramStr' : paramStr
								});
							}
							if ($('#importData2').length > 0) {
								$('#importData2').uploadify('settings', 'formData', {
									'paramStr' : paramStr
								});
							}
							if ($('#importData3').length > 0) {
								$('#importData3').uploadify('settings', 'formData', {
									'paramStr' : paramStr
								});
							}
							if ($('#importData4').length > 0) {
								$('#importData4').uploadify('settings', 'formData', {
									'paramStr' : paramStr
								});
							}
							if ($('#importCampData').length > 0) {
								$('#importCampData').uploadify('settings', 'formData', {
									'paramStr' : paramStr
								});
							}

							if ($('#importData31').length > 0) {
								$('#importData31').uploadify('settings', 'formData', {
									'paramStr' : paramStr
								});
							}
							if ($('#importData32').length > 0) {
								$('#importData32').uploadify('settings', 'formData', {
									'paramStr' : paramStr
								});
							}
							if ($('#importData33').length > 0) {
								$('#importData33').uploadify('settings', 'formData', {
									'paramStr' : paramStr
								});
							}
							if ($('#importData34').length > 0) {
								$('#importData34').uploadify('settings', 'formData', {
									'paramStr' : paramStr
								});
							}
						}
					} catch (e) {
					}
				},
				'onUploadSuccess' : function(file, data, response) {
					if(response == true){
						var json = eval('(' + data + ')');
						if(json.success == true){
							cfg.onSuccess.call(this, file, json,btnId);
						}else{
							if(cfg.onFail){
								cfg.onFail.call(this, file, json,btnId);
							}else{
								if(json.type == 'document'){
									alert(localeMsg.attach.typeError);
								}else{
									alert(localeMsg.attach.serverError);
								}
							}
						}
					}else{
						alert(localeMsg.common.contactAdmin);
					}
		    	}
			};
			delete params.buttonImage;
			if(cfg.text){
				params.buttonText = cfg.text;
				
			}
			
			// 上传
			btn.uploadify(params);
			
			// 修改上传按钮样式
			$("#" + btnId + "-button").removeAttr("style");
			$("#" + btnId + "-button").removeClass();
			$("#" + btnId).removeAttr("style");
			$("#" + btnId).removeClass();
			//$("#" + btnId).attr("style","margin-left:15px;");
			//$("#" + btnId).addClass("s_btnwork");
			//$("#" + btnId).attr("style","float:left;");
			$("#" + btnId).attr("style","width:25px;text-decoration:none;height: 24px;display: block;float: left;line-height: 24px;color: #2477b3;text-decoration: none;margin-left: 15px;");
			//$("#" + btnId):hover.attr("style","color:#e2812b;");
				
			$("#" + btnId+ "-button").find("span").hover(
			  function () {
				$(this).attr("style","color:#e2812b;");
			  },
			  function () {
				//$(this).attr("style","color:#e2812b;");
			  }
			);

			$("#" + btnId+ "-button").find("span").removeClass();
			$("#" + btnId+ "-button").find("span").attr("style","color: #2477b3;padding-left:0px;");
			//$("#SWFUpload_0").attr("style","margin-left:-30px");
			$("#SWFUpload_0").removeClass();
			
			
			
			function onSwfSelectError(file, errorCode, errorMsg){
				if(errorCode == SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT){
					alert(localeMsg.attach.maxSize);
					return false;
				}else if(errorCode == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE){
					alert(localeMsg.attach.attachExist);
					return false;
				}else if(errorCode == SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED){
					alert(localeMsg.attach.maxAttach);
					return false;
				}
			}
		},
		
		/**
		 * 上传成功后的默认回调方法
		 */
		defaultUploadCallback: function() {
			alert(params);
		},
		onSelect: function(file)
		{ 
			//文件名称
			$("#templateName").val(file.name);
		}
	}

var fileuploadNoPermission = {
		
		/**
		 * 上传附件，带进度条
		 * @param btnId 上传按钮id
		 * @cfg 设置信息 {onSuccess:callback, type:fileType[image|doc]}
		 * 示例：fileUpload.swfupload("uploadBtn", {convert:true,onSuccess:callbackUpload});
		 */
		swfupload:function(btnId,cfg){
			var btn = $("#"+btnId);
			var data = cfg.convert ? {'convert':'1'} : {};
			
			var limit = cfg.limit || 99;
			
			var url = cfg.fileUploadUrl || '/file/upload';

			var param = "?companyId="+companyId;
			var attachType = cfg.attachType ? cfg.attachType : "OTHER_ATTACH";
			param  += "&attachType="+attachType;
			var businessCode = cfg.businessCode ? cfg.businessCode : "default";
			param  += "&businessCode="+businessCode;
			
			url = url +param;
			
			var fileExt = null; // 允许上传文件的扩展名
			if(cfg.type == "image"){
				fileExt = "*.jpg;*.jpeg;*.gif;*.png";
			} else if(cfg.type == "doc"){
				fileExt = "*.doc;*.docx;*.xls;*.xlsx;*.ptt;*.pptx;*.pdf;*.txt";
			} else if(cfg.type == "pdf"){
				fileExt = "*.pdf";
			} else if(cfg.type == "word"){
				fileExt = "*.doc;*.docx";
			}else {
			    //按黄楠要求，改成可上传所有文件
				fileExt = "*.*";
			}
			var params = {
				'height'        : 25,
				'width'         : 76,
				'fileObjName'   : 'file',
				'formData'      : data,
				'fileTypeExts'	: fileExt,
				'fileSizeLimit' : cfg.sizeLimit || '30MB', 
				'onSelectError' : onSwfSelectError,
				'overrideEvents' : ['onSelectError','onDialogClose'],
				'swf'      : resourceURL + '/uploadify/uploadify.swf',
				'uploader' :  fileURL + url,
				'auto' : true,
				'multi' : false,
				'scriptAccess' : 'always',
				'removeTimeout' : 1,
				'successTimeout' : 120,
				'uploadLimit':limit,
				'buttonText' :'<a href="javascript:void(0);">'+localeMsg.attach.upload+'</a>',
				'removeCompleted' : true,
				'onUploadSuccess' : function(file, data, response) {
					if(response == true){
						var json = eval('(' + data + ')');
						if(json.success == true){
							cfg.onSuccess.call(this, file, json,btnId);
						}else{
							if(cfg.onFail){
								cfg.onFail.call(this, file, json,btnId);
							}else{
								if(json.type == 'document'){
									alert(localeMsg.attach.typeError);
								}else{
									alert(localeMsg.attach.serverError);
								}
							}
						}
					}else{
						alert(localeMsg.common.contactAdmin);
					}
		    	}
			};
			
			if(cfg.text){
				params.buttonText = cfg.text;
				params.buttonClass='up-text';
				delete params.buttonImage;
			}
			
			// 上传
			btn.uploadify(params);
			
			// 修改上传按钮样式
			$("#" + btnId + "-button").removeAttr("style");
			$("#" + btnId + "-button").removeClass();
			$("#" + btnId).removeAttr("style");
			$("#" + btnId).removeClass();
			$("#" + btnId).addClass("s_btnwork");
			
			function onSwfSelectError(file, errorCode, errorMsg){
				if(errorCode == SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT){
					alert(localeMsg.attach.maxSize);
					return false;
				}else if(errorCode == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE){
					alert(localeMsg.attach.attachExist);
					return false;
				}else if(errorCode == SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED){
					alert(localeMsg.attach.maxAttach);
					return false;
				}
			}
		},
		
		/**
		 * 上传成功后的默认回调方法
		 */
		defaultUploadCallback: function() {
			alert(params);
		},
		onSelect: function(file)
		{ 
			//文件名称
			$("#templateName").val(file.name);
		}
	}

/**
 * 上传个人图片
 */
var mypicUpload = {
		
		/**
		 * 上传附件，带进度条
		 * @param btnId 上传按钮id
		 * @cfg 设置信息 {onSuccess:callback, type:fileType[image|doc]}
		 * 示例：fileUpload.swfupload("uploadBtn", {convert:true,onSuccess:callbackUpload});
		 */
		swfupload:function(btnId,cfg){
			var btn = $("#"+btnId);
			var data = cfg.convert ? {'convert':'1'} : {};
			
			var limit = cfg.limit || 99;
			
			var fileExt = "*.jpg;*.jpeg;";// 允许上传文件的扩展名
			var sizeLimit=cfg.sizeLimit || '30MB';
			var params = {
				'height'        : 25,
				'width'         : 76,
				'fileObjName'   : 'file',
				'formData'      : data,
				'fileTypeExts'	: fileExt,
				'fileSizeLimit' : cfg.sizeLimit || '30MB', 
				'onSelectError' : onSwfSelectError,
				'overrideEvents' : ['onSelectError','onDialogClose'],
				'swf'      : resourceURL + '/uploadify/uploadify.swf',
				'uploader' :  fileURL + '/file/uploadHeadPic',
				'auto' : true,
				'multi' : false,
				'scriptAccess' : 'always',
				'removeTimeout' : 1,
				'successTimeout' : 120,
				'uploadLimit':limit,
				'buttonText' :'<a href="javascript:void(0);">'+localeMsg.attach.upload+'</a>',
				'removeCompleted' : true,
				'onUploadSuccess' : function(file, data, response) {
					if(response == true){
						var json = eval('(' + data + ')');
						if(json.success == true){
							cfg.onSuccess.call(this, file, json,btnId);
						}else{
							if(cfg.onFail){
								cfg.onFail.call(this, file, json,btnId);
							}else{
								if(json.type == 'document'){
									alert(localeMsg.attach.typeError);
								}else{
									alert(localeMsg.attach.serverError);
								}
							}
						}
					}else{
						alert(localeMsg.common.contactAdmin);
					}
		    	}
			};
			
			if(cfg.text){
				params.buttonText = cfg.text;
				params.buttonClass='up-text';
				delete params.buttonImage;
			}
			
			// 上传
			btn.uploadify(params);
			
			// 修改上传按钮样式
			$("#" + btnId + "-button").removeAttr("style");
			$("#" + btnId + "-button").removeClass();
			$("#" + btnId).removeAttr("style");
			$("#" + btnId).removeClass();
			$("#" + btnId).addClass("s_btnwork");
			
			function onSwfSelectError(file, errorCode, errorMsg){
				if(errorCode == SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT){
					alert('附件不能超过'+sizeLimit);
					return false;
				}else if(errorCode == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE){
					alert(localeMsg.attach.attachExist);
					return false;
				}else if(errorCode == SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED){
					alert(localeMsg.attach.maxAttach);
					return false;
				}
			}
		},
		
		/**
		 * 上传成功后的默认回调方法
		 */
		defaultUploadCallback: function() {
			alert(params);
		},
		onSelect: function(file)
		{ 
			//文件名称
			$("#templateName").val(file.name);
		}
	}
